SET(PLUGIN_FILES "")
IF(LMMS_BUILD_WIN32)
	INSTALL(FILES $<TARGET_FILE:Qt5::QWindowsIntegrationPlugin> DESTINATION platforms)
ENDIF()

IF(LMMS_BUILD_WIN32 OR LMMS_INSTALL_DEPENDENCIES)
	include(InstallTargetDependencies)

	# Collect directories to search for DLLs
	GET_FILENAME_COMPONENT(QTBIN_DIR "${QT_QMAKE_EXECUTABLE}" PATH)
	set(LIB_DIRS "${QTBIN_DIR}")

	GET_PROPERTY(PLUGINS_BUILT GLOBAL PROPERTY PLUGINS_BUILT)

	IF(LMMS_BUILD_WIN32)
		SET(LMMS_DEP_DESTINATION ${BIN_DIR})
		SET(PLUGIN_DEP_DESTINATION ${BIN_DIR})
	ELSE()
		SET(LMMS_DEP_DESTINATION ${LIB_DIR})
		SET(PLUGIN_DEP_DESTINATION ${LIB_DIR})
	ENDIF()

	INSTALL_TARGET_DEPENDENCIES(
			NAME "main_binary"
			TARGETS lmms
			DESTINATION "${LMMS_DEP_DESTINATION}"
			LIB_DIRS  ${LIB_DIRS}
	)

	INSTALL_TARGET_DEPENDENCIES(
			NAME "plugins"
			TARGETS ${PLUGINS_BUILT}
			DESTINATION ${PLUGIN_DEP_DESTINATION}
			LIB_DIRS ${LIB_DIRS} "${PLUGIN_DIR}" "${PLUGIN_DIR}/optional"
			SEARCH_PATHS "${PLUGIN_DIR}" "${PLUGIN_DIR}/optional"
	)
ENDIF()

# Install STK rawwaves
if(LMMS_HAVE_STK AND (LMMS_BUILD_WIN32 OR LMMS_BUILD_APPLE))
	if(STK_RAWWAVE_ROOT)
		file(GLOB RAWWAVES "${STK_RAWWAVE_ROOT}/*.raw")
		install(FILES ${RAWWAVES} DESTINATION "${DATA_DIR}/stk/rawwaves")
	else()
		message(WARNING "Can't find STK rawwave root!")
	endif()
endif()

IF(LMMS_BUILD_APPLE)
	INSTALL(CODE "EXECUTE_PROCESS(COMMAND chmod u+x ${CMAKE_BINARY_DIR}/install_apple.sh)")
	INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_BINARY_DIR}/install_apple.sh RESULT_VARIABLE EXIT_CODE)
		IF(NOT EXIT_CODE EQUAL 0)
			MESSAGE(FATAL_ERROR \"Execution of install_apple.sh failed\")
		ENDIF()
	")
ENDIF()
